﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Linq;
using System.Collections.Generic;
using Interfaces.Inherited_Interfaces;
using Interfaces.Add_Interfaces;
using Presenters.Add_Presenters;
using Model.Domain_Model;
using Views.Status_Views;

namespace Views.Add_Views
{
    public partial class RoadNewView : Form, IRoadAddView
    {
        RoadNewPresenter presenter = null;

        public RoadNewView()
        {
            InitializeComponent();
            presenter = new RoadNewPresenter(this);
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            presenter.GetCurrencyList();
            presenter.GetTypeRoadList();
        }

        string IRoadAddView.fromCity
        {
            get
            {
                return fromCity.Text;
            }
            set
            {
                fromCity.Text = value as string;
            }
        }

        string IRoadAddView.fromCountry
        {
            get
            {
                return fromCountry.Text;
            }
            set
            {
                fromCountry.Text = value as string;
            }
        }

        bool IRoadAddView.isDedicated
        {
            get
            {
                return isDedicated.Checked;
            }
            set
            {
                isDedicated.Checked = value;
            }
        }

        string IRoadAddView.linkToMap
        {
            get
            {
                return linkToMap.Text;
            }
            set
            {
                linkToMap.Text = value as string;
            }
        }

        string IRoadAddView.toCity
        {
            get
            {
                return toCity.Text;
            }
            set
            {
                toCity.Text = value as string;
            }
        }

        string IRoadAddView.toCountry
        {
            get
            {
                return toCuntry.Text;
            }
            set
            {
                toCuntry.Text = value as string;
            }
        }

        void ICloseable.Close()
        {
            this.Close();
        }

        T IView.ReturnView<T>()
        {
            return (T)((object)this);
        }

        void IError.ShowError()
        {
            presenter.ShowError(new ErrorView());
        }

        void ISuccess.ShowSuccess()
        {
            presenter.ShowSuccess(new SuccessView());
        }

        void Interfaces.General_Interfaces.IParamable.SetParams(params object[] param)
        {
            presenter.client = (Client)param.Where(x => x.GetType() == typeof(Client)).FirstOrDefault();
        }

        string IRoadAddView.clientNameCorporation
        {
            get
            {
                return nameCorporation.Text;
            }
            set
            {
                nameCorporation.Text = value as string;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            presenter.Save();
        }


        Model.Domain_Model.Currency IRoadAddView.currency
        {
            get
            {
                return (Currency)currency.SelectedItem;
            }
            set
            {
                currency.SelectedItem = value as Currency;
            }
        }

        Model.Domain_Model.TypeRoad IRoadAddView.type
        {
            get
            {
                return (TypeRoad)type.SelectedItem;
            }
            set
            {
                type.SelectedItem = value as TypeRoad;
            }
        }

        Model.Domain_Model.Valuation IRoadAddView.voluation
        {
            get
            {
                return new Valuation { };
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        private void label10_Click(object sender, EventArgs e)
        {
            presenter.SearchClientDisplay(new SearchClientView());
        }


        System.Collections.Generic.IList<Currency> IRoadAddView.currencyList
        {
            get
            {
                return (List<Currency>)currency.DataSource;
            }
            set
            {
                currency.DataSource = value as List<Currency>;
            }
        }


        IList<TypeRoad> IRoadAddView.typeRoadList
        {
            get
            {
                return (List<TypeRoad>)type.DataSource;
            }
            set
            {
                type.DataSource = value as List<TypeRoad>;
            }
        }


        double IRoadAddView.value
        {
            get
            {
                return Convert.ToDouble(value.Text);
            }
            set
            {
                throw new NotImplementedException();
            }
        }
    }
}
